package com.harmontronics.hanma.paas.paas.domain.app.repository.persistence;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.harmontronics.hanma.paas.paas.consts.DbConstants;
import com.harmontronics.hanma.paas.paas.consts.NumberEnum;
import com.harmontronics.hanma.paas.paas.domain.app.entity.valueobject.Fields;
import com.harmontronics.hanma.paas.paas.domain.app.repository.mapper.HmModelPublishMapper;
import com.harmontronics.hanma.paas.paas.domain.app.repository.po.HmModelPublishPO;
import org.springframework.stereotype.Repository;


@Repository("hmModelPublishRepository")
public class HmModelPublishRepository extends ServiceImpl<HmModelPublishMapper, HmModelPublishPO> {

    public IPage<HmModelPublishPO> selectPage(QueryWrapper<HmModelPublishPO> queryWrapper, Page<HmModelPublishPO> page) {
        return baseMapper.selectPage(page, queryWrapper);
    }


    public List<HmModelPublishPO> findByModelId(Long modelId){
        QueryWrapper<HmModelPublishPO> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq(Fields.MODEL_ID,modelId);
        queryWrapper.orderByDesc(DbConstants.CREATE_DATE);
        return baseMapper.selectList(queryWrapper);
    }

    public HmModelPublishPO findActivatedByModelId(Long modelId){
        QueryWrapper<HmModelPublishPO> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq(Fields.MODEL_ID,modelId);
        queryWrapper.eq(Fields.ACTIVATED, NumberEnum.ONE.getNum());
        return baseMapper.selectOne(queryWrapper);
    }
}